<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<%@ page import="com.conversationboard.config.*" %>
<%@ page import="com.conversationboard.model.StyleSheets"%>

<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>

<%@ page import="com.conversationboard.view.MainMenu"%>
<%@ page import="com.conversationboard.controller.confirm.Confirm"%>
<%@ page import="java.util.*"%>
<%@ page import="com.conversationboard.model.User"%>
<%@ page import="com.conversationboard.model.Boards"%>
<%@ page import="com.conversationboard.model.Board"%>

<%
	String key = Confirm.getKey(request.getUserPrincipal().getName());
	User user = User.get(request.getUserPrincipal());
	List<Integer> boardShortcuts = user.getPreferences().getBoardShortcuts();
	Map<Integer, Integer> boardShortcutsMap = new HashMap<Integer, Integer>();
	
	for (int boardShortcut : boardShortcuts) {
		boardShortcutsMap.put(boardShortcut, boardShortcut);
	}
	
	List<Board> boards = Boards.getAuthorisedBoards(user, false);
	boolean useBoardShortcuts = user.getPreferences().isUseBoardShortcuts();

	request.setAttribute("user", user);
	request.setAttribute("boardShortcuts", boardShortcuts);
	request.setAttribute("boardShortcutsMap", boardShortcutsMap);
	request.setAttribute("boards", boards);
	request.setAttribute("useBoardShortcuts", useBoardShortcuts);
	
%>

<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Customise Site View</title>
		<link rel="stylesheet"title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>

		<%= MainMenu.display(request.getUserPrincipal()) %>
	
		<div class="headingblock">
			<h1>Customise Board Shortcuts</h1>
		</div>

		<div class="mainblock">
			<div class="formsection">
			
				<h2>Message Boards</h2>

				<p>Select the boards you wish to show on your menu bar.</p> 

				<form action="${contextPath}/UpdateBoardShortcutsControllerServlet?restoreDefaults=true" method="post">
					<%= key %>					
				 	<input type="submit" value="Restore Defaults" />
				</form>
				
				<form class="formsectionlight" action="${contextPath}/UpdateBoardShortcutsControllerServlet" method="post">
					<%= key %>					
					<table class="table">
						
						<tr class="header">
							<td class="cell">Board Name</td>
							<td class="cell">Show?</td>
						</tr>			
					
						<c:forEach var="board" items="${boards}">
							<tr class="row">
								<td class="cell">${board.name}</td>
								
								<c:if test="${useBoardShortcuts}">
									<c:choose>
										<c:when test="${boardShortcutsMap[board.boardId] ne null}">
											<td class="cell"><input type="checkbox" name="show${board.boardId}" value="true" CHECKED /></td>
										</c:when>
	
										<c:otherwise>
											<td class="cell"><input type="checkbox" name="show${board.boardId}" value="true" /></td>
										</c:otherwise>								
									</c:choose>
								</c:if>

								<c:if test="${not useBoardShortcuts}">
									<c:choose>
										<c:when test="${board.popularBoard}">
											<td class="cell"><input type="checkbox" name="show${board.boardId}" value="true" CHECKED /></td>
										</c:when>
	
										<c:otherwise>
											<td class="cell"><input type="checkbox" name="show${board.boardId}" value="true" /></td>
										</c:otherwise>								
									</c:choose>
								</c:if>
								
							</tr>
						</c:forEach>
					</table>
	
					<br />
				 	<input type="submit" value="   Update My Board Shortcuts   " />
				</form>

			</div>
		</div>
			
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
